<template>
  <div class="app-container">
    <el-form :model="searchForm" label-width="80px">
      <el-row>
        <!--<el-col v-if="roleType===0" class="other">-->
          <!--<el-form-item label="所属团队" size="small">-->
            <!--<el-input v-model="searchForm.teamName"></el-input>-->
          <!--</el-form-item>-->
        <!--</el-col>-->
        <el-col class="other">
          <el-form-item label="姓名" size="small">
            <el-input v-model="searchForm.applyName"></el-input>
          </el-form-item>
        </el-col>
        <el-col class="other">
          <el-form-item label="应聘岗位" size="small">
            <el-input v-model="searchForm.station"></el-input>
          </el-form-item>
        </el-col>
        <el-col class="searchBtn">
          <el-form-item size="small">
            <el-button type="primary" icon="el-icon-search" @click="search()">搜索</el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div class="table-btn">
      <!--<el-button size="small" icon="el-icon-upload2">导出</el-button>-->
    </div>
    <my-table
      :data="tableData"
      :col-configs="colConfigs"
      v-loading="listLoading"
      :page-num="pageNum"
      :page-size="pageSize"
    >
    </my-table>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="pageNum"
      :page-sizes="[10, 20, 30, 40]"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total">
    </el-pagination>
  </div>
</template>

<script>
  import {
    getFeedback
  } from '@/api/feedback'
  import myTable from '@/components/myTable'

  import { Message } from 'element-ui'
  import { AreaSelect } from 'vue-area-linkage'
  import { pca } from 'area-data'
  import { formatDate } from '@/utils/index'

  const sex = function(row, column) {
    return row.sex ? '男' : '女'
  }

  const time = {
    props: ['colConfig'],
    filters: {
      formatDate(time) {
        var date = new Date(time)
        return formatDate(date, 'yyyy-MM-dd')
      },
      formatTime(time) {
        var date = new Date(time)
        return formatDate(date, 'yyyy-MM-dd hh:mm:ss')
      }
    },
    template: `
  <el-table-column :label="colConfig.label" :width="colConfig.width">
            <el-table-column  v-for="(item, index) in colConfig.children"  :label="item.label" :width="item.width">
                <span slot-scope="scope" >{{scope.row[item.prop]}}</span>
            </el-table-column>
  </el-table-column>
  `
  }

  export default {
    components: {
      myTable,
      AreaSelect
    },
    data() {
      return {
        colConfigs: [
          { prop: 'applyName', label: '姓名', width: '150', fixed: true },
          { prop: 'sex', label: '性别', width: '100', formatter: sex },
          { prop: 'age', label: '年龄', width: '100' },
          { prop: 'tel', label: '联系电话', width: '150' },
          { prop: 'station', label: '应聘岗位', width: '150' },
          { prop: 'way', label: '方式', width: '150' },
          { prop: 'source', label: '来源', width: '150' },
          {
            label: '时间', width: '300', children: [
              { prop: 'weekDay', label: '星期', width: '150' },
              { prop: 'applyTime', label: '日期', width: '150' }
            ], component: time
          },
          {
            label: '约试', width: '600', children: [
              { prop: 'isResult', label: '邀约结果', width: '150' },
              { prop: 'interviewTime', label: '面试时间', width: '150' },
              { prop: 'status', label: '状态', width: '150' },
              { prop: 'tryRemark', label: '备注', width: '150' }
            ], component: time
          },
          { prop: 'firstTry', label: '人事初试', width: '150' },
          { prop: 'repeatTry', label: '用人部门复试', width: '150' },
          { prop: 'finalTry', label: '终试', width: '150' },
          { prop: 'isEntry', label: '入职', width: '150' },
          { prop: 'result', label: '面试结果', width: '150' },
          { prop: 'teamName', label: '用人部门', width: '150' },
          { prop: 'remark', label: '备注', width: '150' },
          { slot: 'opt' }
        ],
        searchForm: {},
        searchFormList: {},
        tenderNames: [],
        infoTitles: [],
        listLoading: true,
        dialogTitle: '新增招聘反馈',
        dialogType: 0,
        teamRow: {},
        teamRowClear: {},
        tableData: [],
        pageNum: 1,
        pageSize: 10,
        total: 1,
        outerVisible: false,
        innerVisible: false,
        pca: pca,
        rules: {
          applyName: [
            { required: true, message: '请输入姓名', trigger: 'change' }
          ],
          station: [
            { required: true, message: '请输入应聘岗位', trigger: 'blur' }
          ],
          sex: [
            { required: true, message: '请选择性别', trigger: 'change' }
          ],
          way: [
            { required: true, message: '请选择方式', trigger: 'change' }
          ],
          age: [
            { required: true, message: '请选择年龄', trigger: 'change' }
          ],
          source: [
            { required: true, message: '请输入来源', trigger: 'blur' }
          ],
          tel: [
            { required: true, message: '请输入联系电话', trigger: 'change' }
          ],
          applyTime: [
            { required: true, message: '请选择日期', trigger: 'change' }
          ],
          weekDay: [
            { required: true, message: '请输入星期', trigger: 'blur' }
          ]
        },
        visible: false
      }
    },
    created() {
      this.teamRowClear = JSON.parse(JSON.stringify(this.teamRow))
      this.fetchData()
    },
    computed: {
      teamId() {
        return this.$store.state.user.teamId
      },
      isDirector() {
        return this.$store.state.user.isDirector
      },
      roleType() {
        return this.$store.state.user.roleType
      },
      teamIds() {
        return this.$store.state.user.teamIds
      }
    },
    methods: {
      fetchData() {
        this.searchFormList.pageNum = this.pageNum
        this.searchFormList.pageSize = this.pageSize
        this.searchFormList.roleType = this.roleType
        this.searchFormList.teamId = this.teamId
        this.searchFormList.teamIds = this.teamIds
        this.listLoading = true
        getFeedback(this.searchFormList).then(response => {
          this.tableData = response.responseBody.list
          this.total = response.responseBody.total
          this.listLoading = false
        })
      },
      search() {
        this.pageNum = 1
        this.searchFormList = JSON.parse(JSON.stringify(this.searchForm))
        this.fetchData()
      },
      handleSizeChange(val) {
        this.pageSize = val
        this.fetchData()
      },
      handleCurrentChange(val) {
        this.pageNum = val
        this.fetchData()
      },
      downloadFile() {
        this.$refs.file.click()
      },
      selectGet(vId) {
        let obj = {}
        obj = this.GLOBAL.subjectionDepartmentList.find((item) => {
          return item.value === vId // 筛选出匹配数据
        })
        this.teamRow.departmentName = obj.label
      }
    },
    mounted() {
      console.log(this.pca)
    }
  }
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  .app-container {
    .el-pagination {
      margin-top: 20px;
    }
    .table-btn {
      margin-bottom: 10px;
      & > button {
        margin: 0 20px;
      }
      .el-dialog {
        textarea {
          margin-top: 10px;
        }
        .el-checkbox {
          margin-right: 20px;
        }
        .el-checkbox + .el-checkbox {
          margin-left: 0;
        }
      }
    }
    .item-inline {
      display: inline-block;
      width: 300px;
    }
    input[type="file"] {
      display: none;
    }
  }

</style>


<style rel="stylesheet/scss" lang="scss">
  .el-input__icon {
    line-height: 100%;
  }

  .el-form-item__content {
    line-height: 33px;
  }

  .area-select .area-selected-trigger {
    padding: 0 10px;
  }

  /*.inner-dialog {*/
  /*.item-inline {*/
  /*display: inline-block;*/
  /*width: 300px;*/
  /*}*/
  /*}*/

  /*.el-table__body tr.hover-row>td {
    background-color: #0000ff !important;
  }

  .el-table__body tr.current-row>td {
    background-color: #0000ff !important;
  }*/
</style>
